
const fn = {
  cookie: {
    get: (key: string) => document.cookie.split(';').find(k => k.trim().startsWith(`${key}=`))?.split('=')[1],
    set: (key: string, value: string) => document.cookie = `${key}=${value}`,
    del: (key: string) => document.cookie = `${key}=;expires=Thu, 01 Jan 1970 00:00:00 GMT`,
  },
  localStorage: {
    get: (key: string) => window.localStorage.getItem(key),
    set: (key: string, value: string) => window.localStorage.setItem(key, value),
    del: (key: string) => window.localStorage.removeItem(key),
  },
  sessionStorage: {
    get: (key: string) => window.sessionStorage.getItem(key),
    set: (key: string, value: string) => window.sessionStorage.setItem(key, value),
    del: (key: string) => window.sessionStorage.removeItem(key),
  },
}

export default (type: keyof typeof fn) => fn[type];
